var book_cat_ops={
	init:function(){
		this.eventBind();
	},
	eventBind:function(){
		//点击保存事件
		$(".save").click(function(){
			var btn_target=$(this);
			var cat_name=$("input[name=name]").val();
			var id=$("input[name=id]").val();
			var cat_name_target=$("input[name=name]");
			var weight=$("input[name=weight]").val();
			var weight_target=$("input[name=weight]");
			if(btn_target.hasClass("disabled")){
				common_ops.alert("正在处理,请不要重复点击!");
				return;
			};
			if($.trim(cat_name).length<1){
				common_ops.tip("分类名称不能为空",cat_name_target);
				return;

			}
			if($.trim(weight).length<1){
				common_ops.tip("权重不能为空",weight_target);
				return;

			}	
			btn_target.addClass("disabled");
			$.ajax({
				url:common_ops.buildWebUrl("/book/cat_set"),
				type:'POST',
				dataType:"json",
				data:{
					cat_name:cat_name,
					weight:weight,
					id:id,
				},
				success:function(res){
					btn_target.removeClass("disabled");
					callback=null;
					if(res.code==200){
						 callback=function(){
						 	window.location.href=window.location.href;
						 };
					}
					common_ops.alert(res.msg,callback);
				},
			});
		});
		//点击删除事件
		$(".remove").click(function(){
			var id=$(this).attr("data");
			
			$.ajax({
				url:common_ops.buildWebUrl('/book/cat_del'),
				type:"POST",
				dataType:"json",
				data:{
					id:id,
				},
				success:function(res){

					callback=null;
					if(res.code==200){
						 callback=function(){
						 	window.location.href=window.location.href;
						 };
					}
					common_ops.alert(res.msg,callback);
				}
			});
		});

	},
};
$(document).ready(function(){
	book_cat_ops.init();
});